﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using System.Web.Services;
using System.Xml;
using System.Web.Script.Services;

namespace GalGame
{
    public partial class Load : System.Web.UI.Page
    {
        private static string _XmlFile = "Xml/script.xml";
        private static string webPath = HttpContext.Current.Server.MapPath("~") + "//";

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
        [WebMethod]
        public static XmlDocument ReadScriptXml(string load, string nowload)
        {
            int load_ = int.Parse(load);
            int nowload_ = int.Parse(nowload);

            XmlDocument scriptXml = new XmlDocument();
            scriptXml.Load(webPath + _XmlFile);
            XmlNodeList nodeList = scriptXml.SelectNodes("GalGame/Load");
            StringBuilder xmlstr = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?><GalGame>");
            for (int i = 0; i < load_; i++)
            {
                if (nowload_ + i < nodeList.Count)
                    xmlstr.Append(nodeList[nowload_ + i].OuterXml);
                else
                    break;
            }
            xmlstr.Append("</GalGame>");
            scriptXml.LoadXml(xmlstr.ToString());
            return scriptXml;
        }
    }
}